<--- %%NOBANNER%% --> prcnt.sas
 BackForward

/*-------------------------------------------------------------------------------\
| SOURCE:   contents.sas                                                         |
|                                                                                |
| VERSION:  RDS v3.0                                                             |
|           Part of the SPIKEware Rapid Decision Support SAS Macro Package       |
|           for SAS v8.x and above                                               |
|                                                                                |
| PURPOSE:  This macro runs a proc contents and prints the first 20 records of   |
|           the input dataset or datasets.  The number of observations can be    |
|           overriddent to a specific value.  The macro can also add a title     |
|           to your output.                                                      |
|                                                                                |
| SYNTAX:   %contents (datalist = _input_datasets_,                    |
|                      data     = _input_dataset_,                     |
|                      obs      = _obs_to_print_,                      |
|                      title    = _yes_or_no_)                         |
\-------------------------------------------------------------------------------*/
%macro prcnt (data=%str(), datalist=%str(), obs=10, title=NO) /des='Get picture of SAS Datasets';
%let notes=%sysfunc(getoption(notes, keyword)) ;
options nonotes ;
%local data datalist obs data num i title ;
%let starttime = %sysfunc(datetime()) ;

/*-------------------------------------------\
| check the data and datalist macro variabls |
\-------------------------------------------*/
%if &datalist = &data and &data = %str() %then %do;
   %let data = %upcase(%scan(&sysdsn, 1).%scan(&sysdsn, 2));
   %put NOTE: No datasets are specified.  The dataset &data will be used.;
%end ;
%else %if &datalist ne &data and &datalist ne %str() and &data ne %str() %then %do;
   %put WARNING: Macro %nrbquote(%)CONTENTS is attempting to resolve input values for;
   %put WARNING: both &DATALIST and &DATA. Only one input value is valid.;
   %put WARNING: The macro will use &DATALIST = "&DATALIST..";
   %let data = &datalist;
%end ;
%else %if &datalist = %str() and &data ne %str() %then %let datalist = &data ;

/*--------------------------------------------------------\
| Set OBS to uppercase check number of words in &datalist |
\--------------------------------------------------------*/
%let num = %words(&data);
%let obs = %upcase(&obs);

%do i = 1 %to &num ;
   %let data = %data(%scan(&datalist, &i, %str( )));
   %let nobs = %nobs(&data);

   %if &title ne NO %then %do;
      title1 "Sample of dataset &data:  &obs of &nobs";
   %end ;

   proc contents data=&data; run;
   %if &obs = _ALL_ %then %do;
      proc print data=&data; run;
   %end;
   %else %do;
      proc print data=&data (obs=&obs); run;
   %end;
%end;

%the_end:;
options nonotes ;
%timenote (macro=contents, starttime=&starttime)
%put; options ¬es;
%mend prcnt;